package com.sikao.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.adapter.PersonalCenterAdapter;
import com.sikao.app.ui.base.BaseActivity;

/**
 * 买家中心
 */
public class BuyersCenterActivity extends BaseActivity implements View.OnClickListener {

	private TextView titleTv;
	private ImageView backIv;
	private ListView listView;
	private PersonalCenterAdapter adapter;
	private String[] titles;
	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_buyers_center);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {
		titles = getResources().getStringArray(R.array.buyer_title);
	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		listView = (ListView) findViewById(R.id.listView);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if (intent == null){
					intent = new Intent();
				}
				switch (position) {
					//买家订单
					case 0:
						intent.setClass(BuyersCenterActivity.this, BuyerOrderActivity.class);
						break;
					//我的评价记录
					case 1:
						intent.setClass(BuyersCenterActivity.this, MyEvaluateActivity.class);
						break;
					//发布招标
					case 2:
						intent.setClass(BuyersCenterActivity.this, ReleaseTenderActivity.class);
						intent.putExtra("releaseInviteState", 1);//发布招标的状态
						break;
					//我发布的招标
					case 3:
						intent.setClass(BuyersCenterActivity.this, MyReleaseTendersActivity.class);
						break;
					//我的拍卖记录
					case 4:
						intent.setClass(BuyersCenterActivity.this, MyAuctionRecordActivity.class);
						break;
					default:
						break;
				}
				startActivity(intent);
			}
		});
	}

	@Override
	protected void init() {
		titleTv.setText("买家中心");
		backIv.setVisibility(View.VISIBLE);
		adapter = new PersonalCenterAdapter(this, titles);
		listView.setAdapter(adapter);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.title_left_img:
				finish();
				break;
			default:
				break;
		}
	}
}
